const Mock = require('mockjs')

const userdata = Mock.mock({
  'userdata|10': [
    {
      userId: '@id',
      admingroupId: '@id',
      // admingroupParentId: "@id",
      admingroupParentId: '-1',
      admingroupName: '@cname',
      admingroupCode: '337788773633',
      sort: '@integer(1,100)',
      createTime: '@date(yyyy-MM-dd HH:mm:ss)',
      createUser: '@cname',
      updateUser: '@id',
      updateTime: '@date(yyyy-MM-dd HH:mm:ss)',
      account: '123123asdasd',
      realName: '@cname',
      children: [
        {
          admingroupId: '@id',
          admingroupParentId: '@id',
          admingroupName: '@cname',
          admingroupCode: '@id',
          sort: '@integer(1,100)',
          createTime: '@date(yyyy-MM-dd HH:mm:ss)',
          createUser: '@id',
          updateUser: '@id',
          updateTime: '@date(yyyy-MM-dd HH:mm:ss)'
        },
        {
          admingroupId: '@id',
          admingroupParentId: '@id',
          admingroupName: '@cname',
          admingroupCode: '@id',
          sort: '@integer(1,100)',
          createTime: '@date(yyyy-MM-dd HH:mm:ss)',
          createUser: '@id',
          updateUser: '@id',
          updateTime: '@date(yyyy-MM-dd HH:mm:ss)'
        }
      ]
    }
  ],
  'userdata1|21': [
    {
      userId: '@id',
      admingroupId: '@id',
      admingroupParentId: '@id',
      admingroupName: '@cname',
      admingroupCode: '337788773633',
      sort: '@integer(1,100)',
      createTime: '@date(yyyy-MM-dd HH:mm:ss)',
      createUser: '@cname',
      updateUser: '@id',
      updateTime: '@date(yyyy-MM-dd HH:mm:ss)',
      account: '123123asdasd',
      realName: '@cname',
      orgName: '@name'
    }
  ],
  persionInfo: {
    userId: 'sssssssdadad',
    account: 'qwmei0hnai9sndi',
    realName: '威龙',
    sex: 'M',
    nickName: '龙龙',
    email: '1111111@qq.com',
    phone: '12344443333',
    avatar: '',
    orgFullPath: '河钢数字/技术中心/基础平台研发部/石家庄研发基地/用户体验部',
    positionName: '哈哈哈哈哈'
  }
})
const data = Mock.mock({
  orgData: [
    {
      orgId: 0,
      orgParentId: '@id',
      orgName: '河钢集团',
      orgFullPath: '@cname',
      children: [
        {
          orgId: 1,
          orgParentId: '@id',
          orgName: '@cname',
          orgFullPath: '@cname',
          children: [
            {
              orgId: 2,
              orgParentId: '@id',
              orgName: '@cname',
              orgFullPath: '@cname'
            }
          ]
        }
      ]
    }
  ]
})

const data1 = Mock.mock({
  applyData: {
    appTypeName: 'aaaaaa',
    'appList|2': [
      {
        id: '@id',
        name: '哈哈',
        code: '@id',
        type: '1',
        version: '3.0',
        children: [
          {
            id: '@id',
            name: '呵呵',
            code: '@id',
            type: '2',
            version: '1.0',
            children: [
              {
                id: '@id',
                name: '嘿嘿',
                code: '@id',
                type: '3',
                version: '2.0'
              }
            ]
          }
        ]
      }
    ]
  }
})
module.exports = [
  {
    url: '/permission/managerGroup/getGroupTree',
    type: 'get',
    response: (config) => {
      return {
        code: '00000',
        success: Boolean(),
        message: '@word(5)',
        data: userdata.userdata
      }
    }
  },
  {
    url: '/permission/managerGroup/add',
    type: 'post',
    response: (config) => {
      return {
        code: '00000',
        success: true,
        message: '@word(5)',
        data: userdata
      }
    }
  },
  {
    url: '/permission/managerGroup/edit',
    type: 'post',
    response: (config) => {
      return {
        code: '00000',
        success: Boolean(),
        message: '@word(5)',
        data: userdata
      }
    }
  },
  // 删除
  {
    url: '/permission/managerGroup/delete',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        data: 'success'
      }
    }
  },
  {
    url: '/permission/managerGroup/getManagerUserPage',
    type: 'get',
    response: (config) => {
      const items = userdata.userdata1
      const { pageNo = 1, pageSize = 10 } = config.query
      const pageList = items.filter(
        (item, index) =>
          index < pageSize * pageNo && index >= pageSize * (pageNo - 1)
      )
      return {
        code: '00000',
        data: {
          totalRows: items.length,
          rows: pageList
        }
      }
    }
  },
  // 移除
  {
    url: '/permission/managerGroup/batchRemoveUsers',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        data: 'success',
        message: '@word(5)'
      }
    }
  },
  // 查询当前被授权的管理员组已经绑定的可授权范围和管理范围
  {
    url: '/permission/managerGroup/getCurrentGroupDataScope',
    type: 'get',
    response: (_) => {
      return {
        code: '00000',
        data: data.orgData
      }
    }
  },
  // 查询当前被授权的管理员组上一级的可授权范围和管理范围
  {
    url: '/permission/managerGroup/getParentGroupDataScope',
    type: 'get',
    response: (config) => {
      const items = data.orgData
      return {
        code: '00000',
        success: Boolean(),
        message: '@word(5)',
        data: items
      }
    }
  },
  // 查询当前被授权的管理员组父级可授权功能和管理功能
  //   {
  //     url: '/permission/managerGroup/getParentGroupFunction',
  //     type: 'get',
  //     response: _ => {
  //       return {
  //         code: '00000',
  //         data: data1.applyData
  //       }
  //     }
  //   },
  // 查询当前被授权的管理员组已绑定的可授权功能和管理功能
  {
    url: '/permission/managerGroup/getCurrentGroupFunction',
    type: 'get',
    response: (_) => {
      return {
        code: '00000',
        data: data1.applyData
      }
    }
  },
  {
    url: '/permission/managerGroup/saveGroupAuthority',
    type: 'post',
    response: (config) => {
      return {
        code: '00000',
        success: true,
        message: '@word(5)'
      }
    }
  },
  {
    url: '/permission/managerGroup/saveManagerUser',
    type: 'post',
    response: (config) => {
      return {
        code: '00000',
        success: true,
        message: '@word(5)'
      }
    }
  },
  {
    url: '/permission/managerGroup/saveGroupAuthority',
    type: 'post',
    response: (config) => {
      return {
        code: '00000',
        success: true,
        message: '@word(5)'
      }
    }
  },
  {
    url: '/permission/managerGroup/getUserDetail',
    type: 'get',
    response: (config) => {
      return {
        code: '00000',
        success: true,
        message: '@word(5)',
        data: userdata.persionInfo
      }
    }
  }
]
